<?php

namespace App\Jobs;

use App\Constant\QueueKey;
use App\Models\UserAuthSpiderTransLog;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class RiskSpiderCacheJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    /**
     * 任务最大尝试次数。
     *
     * @var int
     */
    public $tries = 5;

    /**
     * 任务运行的超时时间。
     *
     * @var int
     */
    public $timeout = 300; //秒数

    /**
     * @var UserAuthSpiderTransLog
     */
    protected $model;

    /*
     * @var $type 爬虫类型 1=运营商 2=芝麻分
     * */
    protected $type;

    /**
     * RiskReptileJob constructor.
     * @param UserAuthSpiderTransLog $model
     * @param $type
     */
    public function __construct(UserAuthSpiderTransLog $model,$type)
    {
        $this->onQueue(QueueKey::QUEUE_RISK_SPIDER_CACHE);
        $this->model = $model;
        $this->type = $type;
    }

    /**
     *
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $model = $this->model;
        if($this->type == UserAuthSpiderTransLog::TYPE_CARRIER){
            \Log::debug('缓存运营商数据完成：'.$model->trade_no);
            UserAuthSpiderTransLog::getStatusByRiskInfo($model->trade_no,$model,$this->type);
        }else{
            \Log::debug('缓存芝麻分数据完成：'.$model->trade_no);
            UserAuthSpiderTransLog::getStatusByRiskInfo($model->trade_no,$model,$this->type);
        }
        return ;
    }
}
